import { DbConfig } from "../../src/config/DbConfig";
import { DaoBase } from "../../src/engine/dao/DaoBase";
import DateUtil from "../../src/engine/utils/DateUtil";
import { Logger } from "../../src/engine/utils/Logger";
import { MysqlClient } from "../../src/engine/utils/MySqlClient";
import { MysqlManager } from "../../src/engine/utils/MysqlManager";

export class SystemSettingDao extends DaoBase {

    public static DB_NAME: string = DbConfig.Db_Name.db_admin;

    public static async update_system_setting(key: string, value: string) {
        let client: MysqlClient = await MysqlManager.instance.getDb(this.DB_NAME);
        let sql: string = "replace into t_system_setting (setting_key,setting_value) values(?,?)"
        let sqlParams = [key, value];
        let results = await client.queryPromise(sql, sqlParams);
        Logger.log("update_system_setting==", sql, sqlParams, results)
        if (results && results["affectedRows"] > 0) {
            return true
        }
        else {
            return false
        }
    }

    public static async get_system_setting(key:string){
        let client: MysqlClient = await MysqlManager.instance.getDb(this.DB_NAME);
        let sql:string = "select * from t_system_setting where setting_key=?"
        let sqlParams = [key];
        let results = await client.queryPromise(sql, sqlParams);
        let setting_value:string = ""
        if (results && results.length > 0) {
            setting_value = results[0]["setting_value"]
        }
        return setting_value 
    }

    public static async get_notice(){
        let client: MysqlClient = await MysqlManager.instance.getDb(this.DB_NAME);
        let sql:string = "select * from t_system_setting where setting_key='notice'"
        let results = await client.queryPromise(sql);
        Logger.log("get_notice==", results)
        let notice:string = ""
        if (results && results.length > 0) {
            notice = results[0]["setting_value"]
        }
        return notice 
    }

    public static async get_choushui(){
        let client: MysqlClient = await MysqlManager.instance.getDb(this.DB_NAME);
        let sql:string = "select * from t_system_setting where setting_key='choushui'"
        let results = await client.queryPromise(sql);
        Logger.log("get_choushui==", results)
        let notice:string = ""
        if (results && results.length > 0) {
            notice = results[0]["setting_value"]
        }
        return notice 
    }

}